package com.bwie.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.espojo.ESShop;
import com.bwie.mapper.ShopMapper;
import com.bwie.pojo.Shop;
import com.bwie.utils.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @description:
 * @author: ykk
 * @create: 2024-10-08 09:45
 **/
@Component
public class ESTask {

    @Autowired
    ElasticsearchRestTemplate elasticsearchRestTemplate;

    @Autowired
    ShopMapper shopMapper;


    @Scheduled(cron = "0 0/1 * * * ?")
    public void esTask(){
        List<Shop> list = shopMapper.selectList(new QueryWrapper<>());
        for (Shop shop : list) {
            ESShop esShop = new ESShop();
            BeanUtils.copyProperties(shop,esShop);
            elasticsearchRestTemplate.save(esShop);
        }
    }
}
